﻿Imports System.Data.OleDb

Public Class uploadPage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit.Click

        If f_Picture.HasFile Then
            Dim picLocationOnServer = Request.MapPath("pictures") & "/" & f_Picture.FileName
            f_Picture.SaveAs(picLocationOnServer)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("MotorcyclesConn").ConnectionString)
        Dim SqlString As String = "Insert into MyTable(Make,Model,Category,Description,DetailedDescription,Difficulty,Picture) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_Make.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Model.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Category.Text)
        cmd.Parameters.AddWithValue("@f4", tb_BriefDescrip.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f6", rbl_Difficulty.SelectedValue)
        cmd.Parameters.AddWithValue("@f7", "pictures/" & f_Picture.FileName)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class